package com.xinghai.system.service.impl;

import java.util.List;
import com.xinghai.common.utils.DateUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import com.xinghai.system.mapper.XhUseVehicleInfoDetailsMapper;
import com.xinghai.system.domain.XhUseVehicleInfoDetails;
import com.xinghai.system.service.IXhUseVehicleInfoDetailsService;

/**
 * 用车信息评论关联Service业务层处理
 * 
 * @author xinghai
 * @date 2024-07-17
 */
@Service
public class XhUseVehicleInfoDetailsServiceImpl implements IXhUseVehicleInfoDetailsService 
{
    @Autowired
    private XhUseVehicleInfoDetailsMapper xhUseVehicleInfoDetailsMapper;

    @Autowired
    private SqlSessionFactory sqlSessionFactory;
    /**
     * 查询用车信息评论关联
     * 
     * @param id 用车信息评论关联主键
     * @return 用车信息评论关联
     */
    @Override
    public XhUseVehicleInfoDetails getInfo(Long id)
    {
        return xhUseVehicleInfoDetailsMapper.getInfo(id);
    }

    @Override
    public XhUseVehicleInfoDetails getEntityByInfoId(Long infoId) {
        return xhUseVehicleInfoDetailsMapper.getEntityByInfoId(infoId);
    }

    /**
     * 查询用车信息评论关联列表
     * 
     * @param xhUseVehicleInfoDetails 用车信息评论关联
     * @return 用车信息评论关联
     */
    @Override
    public List<XhUseVehicleInfoDetails> list(XhUseVehicleInfoDetails xhUseVehicleInfoDetails)
    {
            xhUseVehicleInfoDetails.setDelFlag("0");
        return xhUseVehicleInfoDetailsMapper.list(xhUseVehicleInfoDetails);
    }

    /**
     * 新增用车信息评论关联
     * 
     * @param xhUseVehicleInfoDetails 用车信息评论关联
     * @return 结果
     */
    @Override
    public int insert(XhUseVehicleInfoDetails xhUseVehicleInfoDetails)
    {
        xhUseVehicleInfoDetails.setCreateTime(DateUtils.getNowDate());
        return xhUseVehicleInfoDetailsMapper.insert(xhUseVehicleInfoDetails);
    }
    /**
     * 批量新增用车信息评论关联
     *
     * @param xhUseVehicleInfoDetailsList 用车信息评论关联
     * @return 结果
     */
    @Override
    public int insertBatch(List<XhUseVehicleInfoDetails> xhUseVehicleInfoDetailsList)
    {
        return xhUseVehicleInfoDetailsMapper.insertBatch(xhUseVehicleInfoDetailsList);
    }
    /**
     * 修改用车信息评论关联
     * 
     * @param xhUseVehicleInfoDetails 用车信息评论关联
     * @return 结果
     */
    @Override
    public int update(XhUseVehicleInfoDetails xhUseVehicleInfoDetails)
    {
        xhUseVehicleInfoDetails.setUpdateTime(DateUtils.getNowDate());
        return xhUseVehicleInfoDetailsMapper.update(xhUseVehicleInfoDetails);
    }

    /**
     * 批量删除用车信息评论关联
     * 
     * @param ids 需要删除的用车信息评论关联主键
     * @return 结果
     */
    @Override
    public int deleteBatch(Long[] ids)
    {
        return xhUseVehicleInfoDetailsMapper.deleteBatch(ids);
    }

    /**
     * 删除用车信息评论关联信息
     * 
     * @param id 用车信息评论关联主键
     * @return 结果
     */
    @Override
    public int delete(Long id)
    {
        return xhUseVehicleInfoDetailsMapper.delete(id);
    }

    /**
     * 导入用车信息评论关联信息
     *
     * @param list 用车信息评论关联信息集合
     * @return 结果
     */
    @Override
    @Transactional
    public boolean importData(List<XhUseVehicleInfoDetails> list){
        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
        try {
            XhUseVehicleInfoDetailsMapper xhUseVehicleInfoDetailsMapper = sqlSession.getMapper(XhUseVehicleInfoDetailsMapper.class);
            list.stream().forEach(item -> xhUseVehicleInfoDetailsMapper.insert(item));
            // 提交数据
            sqlSession.commit();
            sqlSession.rollback();
        } catch (Exception e) {
            sqlSession.rollback();
            return false;
        } finally {
            sqlSession.close();
        }
        return true;
    }
}
